#! /bin/bash
# Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Florian La Roche <feedback@suse.de>, 1996
#      Werner Fink <werner@suse.de>, 1996
#      Burchard Steinbild <feedback@suse.de>, 1996
#
# /etc/init.d/nfs
#
### BEGIN INIT INFO
# Provides:       nfs
# Required-Start: $network $portmap
# Required-Stop:
# X-Vendor-Should-Start: nfslock
# X-Vendor-Should-Stop:
# Default-Start:  3 5
# Default-Stop:
# Description:    Imports remote Network File Systems (NFS)
### END INIT INFO

. /etc/rc.status

nfs=no
while read  where what type options rest  ; do
    case "$where" in
	\#*|"") ;;
	*) if test "$type" = "nfs" ; then
		nfs=yes
		break
	   fi ;;
    esac
done < /etc/fstab

rc_reset
case "$1" in
    start|reload)
	echo -n "Importing Net File System (NFS)"
	if test "$nfs" = yes ; then
	# Mount all auto NFS devices (-> nfs(5) and mount(8) )
	#  NFS-Server sometime not reachable during boot phase.
	#  It's sometime usefull to mount NFS devices in
	#  background with an ampersand (&) and a sleep time of
	#  two or more seconds, e.g:
	#  
	#   mount -at nfs &
	#   sleep 2 
	#  
	#  Note: Some people importing the /usr partition.
	#        Therefore we do _NOT_ use an ampersand!
	#
	  mount -at nfs
	  rc_status
	  sleep 1
	#
    	# generate new list of available shared libraries
	#
	  ldconfig -X 2>/dev/null
	  rc_status -v
	else
	  rc_status -u
	fi
	;;
    stop)
	echo -n "Remove Net File System (NFS)"
	if test "$nfs" = "yes" ; then
	  #
	  # Unmount in background because during long timeouts
	  #
	  umount -at nfs &
	  sleep 2
	  rc_status -v
	else
	  rc_status -u
	fi
	;;
    restart|force-reload)
        ## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start
	rc_status
	;;
    status)
	echo -n "Checking for mounted nfs shares (from /etc/fstab):"
	if test "$nfs" = "yes" ; then
	  while read  where what type options rest  ; do
	    case "$where" in
	      \#*|"") ;;
	      *) case "$options" in
		   *noauto*) ;;
		   *) if test "$type" = "nfs" ; then
			grep -q "$where $what nfs" /proc/mounts || rc_failed 3
		      fi ;;
		 esac
	    esac
          done < /etc/fstab
        else
	  rc_failed 3
	fi
        rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|reload|force-reload|restart}"
	exit 1
esac
rc_exit
